package com.longxi.tianjintianbao.ui.activity.maintain;

import android.content.Intent;
import android.support.v4.view.ViewPager;

import com.flyco.tablayout.SlidingTabLayout;
import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.ui.base.BaseActivity;
import com.longxi.tianjintianbao.ui.presenter.maintain.MaintainListAtPresenter;
import com.longxi.tianjintianbao.ui.view.maintain.IMaintainListAtView;

import butterknife.BindView;

public class MaintainListActivity extends BaseActivity<IMaintainListAtView, MaintainListAtPresenter> implements IMaintainListAtView {

    private final String TAG = "MaintainListActivity";

    @BindView(R.id.tabLayout)
    SlidingTabLayout mTabLayout;
    @BindView(R.id.vp)
    ViewPager mViewPager;

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_general_tab;
    }

    @Override
    public void initData() {
        super.initData();
        mPresenter.setBar();

        mPresenter.initViewPager();
        mIvRight.setOnClickListener(v -> mPresenter.saveInspection());
    }

    @Override
    public void initListener() {
        super.initListener();
    }

    @Override
    protected MaintainListAtPresenter createPresenter() {
        return new MaintainListAtPresenter(this);
    }

    @Override
    public SlidingTabLayout getTabLayout() {
        return mTabLayout;
    }

    @Override
    public ViewPager getViewPager() {
        return mViewPager;
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(RESULT_OK != resultCode){
            return;
        }
        mPresenter.refreshFragmentUi();
        mPresenter.setUINoUploadData();
        mTabLayout.showMsg(1, (int) mPresenter.count);
        mTabLayout.setMsgMargin(1, 0, 10);
    }

    public void setTabLayoutMsgCount(int msgCount){
        getTabLayout().showMsg(0, msgCount);
        getTabLayout().setMsgMargin(0, 0, 10);
    }
}
